/**   
* @Title: SpUtil.java 
* @Package com.jiuyang.baoxian.util 
* @Description: TODO(用一句话描述该文件做什么) 
* @author ChangJianlong   
* @date 2014-12-10 上午11:05:34 
* @version V1.0   
*/
package com.bxd.baodan.util;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.bxd.baodan.App;
import com.bxd.baodan.app.SharedPreferanceKey;

/** 
 * @ClassName: SpUtil 
 * @Description: TODO(这里用一句话描述这个类的作用) 
 * @author ChangJianlong 
 * @date 2014-12-10 上午11:05:34 
 *  
 */
public class SpUtil {
	private static final String SP_NAME ="wenwen_sp";
	private static final String SEARCH_HISTORY ="search_history";
	private static SpUtil uniqueInstance = null;
	   
    private SpUtil() {  
       // Exists only to defeat instantiation.  
    }  
   
    public static SpUtil getInstance() {  
       if (uniqueInstance == null) {  
           uniqueInstance = new SpUtil();  
       }  
       return uniqueInstance;  
    }  
    public void savaLong(String key,long value){
    	SharedPreferences sp = PreferenceManager
    	        .getDefaultSharedPreferences(App.getContext());
    	sp.edit().putLong(key, value).commit();
    }
    public long getLong(String key){
    	SharedPreferences sp = PreferenceManager
    	        .getDefaultSharedPreferences(App.getContext());
    	return sp.getLong(key, 0);
    }
    public void savaInteger(String key,int value){
    	SharedPreferences sp = PreferenceManager
    			.getDefaultSharedPreferences(App.getContext());
    	sp.edit().putInt(key, value).commit();
    }
    public int getInteger(String key){
    	SharedPreferences sp = PreferenceManager
    			.getDefaultSharedPreferences(App.getContext());
    	return sp.getInt(key, 0);
    }
    public void savaBoolean(String key,boolean value){
    	SharedPreferences sp = PreferenceManager
    	        .getDefaultSharedPreferences(App.getContext());
    	sp.edit().putBoolean(key, value).commit();
    }
    public String getString(String key){
    	SharedPreferences sp = PreferenceManager
    			.getDefaultSharedPreferences(App.getContext());
    	return sp.getString(key,"");
    }
    public void remove(String key){
    	SharedPreferences sp = PreferenceManager
    			.getDefaultSharedPreferences(App.getContext());
    	sp.edit().remove(key).commit();
    }
    public void savaString(String key,String value){
    	
    	SharedPreferences sp = PreferenceManager
    			.getDefaultSharedPreferences(App.getContext());
    	sp.edit().putString(key, value).commit();
    }
    public boolean getBoolean(String key){
    	SharedPreferences sp = PreferenceManager
    	        .getDefaultSharedPreferences(App.getContext());
    	if(SharedPreferanceKey.IS_FIRST_START.equals(key)||
				SharedPreferanceKey.RECEIVE_SYSTEM_PUSH.equals(key) ||
				SharedPreferanceKey.RECEIVE_NEW_NOTIF.equals(key)||
				SharedPreferanceKey.IS_WEL_FIRST_START.equals(key)){
        	return sp.getBoolean(key, true);
        }
    	return sp.getBoolean(key, false);
    }

	public void clearCache() {
		SharedPreferences sp = PreferenceManager
    	        .getDefaultSharedPreferences(App.getContext());
		sp.edit().clear().commit();
	}
}
